package com.appspot.checkflames.utils;

import java.util.Arrays;

public class FlamesUtils {
	
	public static int calculateFlames(String name1,String name2) {
	    name1 = name1.replace(" ", "");
	    name2 = name2.replace(" ", "");
	    name1.toUpperCase();
	    name2.toUpperCase();
	    char [] name1Arr = name1.toCharArray();
	    char [] name2Arr = name2.toCharArray();
	    Arrays.sort(name1Arr);
	    Arrays.sort(name2Arr);
	    int i=0,j=0;
	    int count=0;
	    while(true) {
	      if(i>=name1Arr.length) {
	        count+=name2Arr.length-j;
	        break;
	      }
	      if(j>=name2Arr.length) {
	        count+=name1Arr.length-i;
	        break;
	      }
	      if(name1Arr[i]==name2Arr[j]) {
	        i++;j++;continue;
	      }
	      if(name1Arr[i]<name2Arr[j]) {
	        i++;count++;
	      } else {
	        j++;count++;
	      }
	    }
	    return josephus(6, count);
	  }
	 
	  private static int josephus(int n,int k) {
	    return n==1 ? 0 : (josephus(n-1,k)+k)%n;
	  }
}
